/*
 * @Description:
 * @Version: 1.0
 * @Author: liguansheng
 * @Date: 2022-08-24 10:13:54
 * @LastEditors: liguansheng
 * @LastEditTime: 2022-08-26 13:06:41
 */
import axios from '@/utils/request'

import {
  IApiResource,
  ICreateApiResource,
  IUpdateApiResource,
} from './types/apiResources'
import { IPageResult } from './types/base'

// 新增api资源详情
export function createApiResource(data: ICreateApiResource) {
  return axios<IApiResource>({
    url: '/api/identity-server/api-resources',
    method: 'post',
    data,
  })
}

// 删除api资源
export function deleteApiResource(id: string) {
  return axios({
    url: '/api/identity-server/api-resources',
    method: 'delete',
    params: {
      id,
    },
  })
}

// 获取api资源详情
export function updateApiResource(id: string, data: IUpdateApiResource) {
  return axios<IApiResource>({
    url: `/api/identity-server/api-resources/${id}`,
    method: 'put',
    data,
  })
}

// 获取api资源
export function pagedApiResource(currentPage = 1, take = 10, filter = '') {
  return axios<IPageResult<IApiResource>>({
    url: '/api/identity-server/api-resources',
    method: 'get',
    params: {
      skipCount: take * (currentPage - 1),
      maxResultCount: take,
      filter,
    },
  })
}

// 获取api资源详情
export function getApiResource(id: string) {
  return axios<IApiResource>({
    url: `/api/identity-server/api-resources/${id}`,
    method: 'get',
  })
}

// 获取所有身份资源
export function getAllApiResources() {
  return axios<IApiResource[]>({
    url: '/api/identity-server/api-resources/all',
    method: 'get',
  })
}
